<!DOCTYPE html>
<html lang="">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button>按钮20</button>
    <button>按钮40</button>
    <button>按钮60</button>
    <p></p>
    <script>
      var btn = document.querySelectorAll("button");
      var str = "闭包把我搞的";
      var p = document.querySelector("p");
      for (var i = 0; i < btn.length; i++) {
        (function (i) {
          btn[i].onclick = function () {
            p.innerHTML = str;
            let size = btn[i].innerText.slice(2) + "px";
            p.style.fontSize = size;
          };
        })(i);
      }
    </script>
  </body>
</html>
